package com.yunxi.controller.vehicle;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.vehicle.pojo.VehicleCertApproveVO;
import com.yunxi.vehicle.pojo.VehicleCertVO;
import com.yunxi.vehicle.service.VehicleCertDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 合格证信息 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-22
 */
@RestController
@RequestMapping("/admin/vehiclecert")
@Api(tags = "pms:vehiclecert", description = "合格证信息接口")
public class VehicleCertController {
   private static final Logger logger = LoggerFactory.getLogger(VehicleCertController.class);

   @Autowired
   VehicleCertDubboService vehicleCertDubboService;

   @GetMapping("/page")
   @ApiOperation(value = "查询分页")
   public ApiResult page(VehicleCertVO vehicleCertVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(vehicleCertDubboService.findPageByVO(vehicleCertVO, pageNum, pageSize));
   }

   @GetMapping("/load")
   @ApiOperation(value = "读取单个")
   public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(vehicleCertDubboService.getById(id));
   }

   @GetMapping("/loadByVin")
   @ApiOperation(value = "读取Vin")
   public ApiResult loadByVin(String vin, @CurrentUser LoginInfo loginInfo) throws Exception {
      return ResponseUtil.ok(vehicleCertDubboService.getByVin(vin));
   }

   @PostMapping("/save")
   @ApiOperation(value = "保存信息")
   public ApiResult save(@RequestBody VehicleCertVO vehicleCertVO, @CurrentUser LoginInfo loginInfo) throws Exception {
      vehicleCertDubboService.saveOrUpdate(vehicleCertVO);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/del")
   @ApiOperation(value = "删除")
   public ApiResult del(@RequestBody List<VehicleCertVO> vehicleCertVOList) throws Exception {
      vehicleCertDubboService.removeByList(vehicleCertVOList);
      return ResponseUtil.ok("success");
   }

   @GetMapping("/managePage")
   @ApiOperation(value = "合格证管理查询分页")
   @ApiImplicitParams({
           @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
           @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
   })
   public ApiResult managePage(VehicleCertVO vehicleCertVO, Integer pageNum, Integer pageSize) throws Exception {
      return ResponseUtil.ok(vehicleCertDubboService.managePage(vehicleCertVO, pageNum, pageSize));
   }

   @PostMapping("/approve")
   @ApiOperation(value = "审核")
   public ApiResult approve(@RequestBody VehicleCertApproveVO vehicleCertApproveVO) throws Exception {
      vehicleCertDubboService.approve(vehicleCertApproveVO);
      return ResponseUtil.ok("success");
   }

   @PostMapping("/transport")
   @ApiOperation(value = "发运")
   public ApiResult transport(@RequestBody VehicleCertApproveVO vehicleCertApproveVO) throws Exception {
      vehicleCertDubboService.transport(vehicleCertApproveVO);
      return ResponseUtil.ok("success");
   }

}
